//
//  LYTrackingManager.swift
//  LYOnlineBanking
//
//  Created by 李永彬 on 2025/8/6.
//

import UIKit
import FBSDKCoreKit

class LYTrackingManager: NSObject {
    
    static func uploadLocationTracking(locationInfo: LYLocationManager.LocationInfo) {
        LYStocksManager.fetchUploadLocationTrackingInfo(locationInfo: locationInfo, nil)
    }
    
    static func uploadDeviceInfoTracking() {
        LYStocksManager.fetchUploadDeviceInfo(nil)
    }
    
    static func uploadGoogleMarketTracking() {
        LYStocksManager.fetchUploadGoogleMarket { googleMarketData, msg, error in
            if error == nil {
                if let factage = googleMarketData?.factage {
                    Settings.shared.appID = factage.stasisry ?? ""
                    Settings.shared.clientToken = factage.eveningsive ?? ""
                    Settings.shared.displayName = factage.removehood ?? ""
                    Settings.shared.appURLSchemeSuffix = factage.biliitor ?? ""
                    ApplicationDelegate.shared.application(UIApplication.shared, didFinishLaunchingWithOptions: nil)
                }
            }
        }
    }
    
    static func uploadRiskTracking(sceneType: SceneType,
                                   productId: Int?,
                                   orderNum: String?,
                                   startTimeStamp: Double,
                                   endTimeStamp: Double) {
        guard appCountryEnv == .indonesia else { return }
        LYLocationManager.shared.requestLocationPermission()
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
            LYStocksManager.fetchUploadRiskInfo(sceneType: sceneType,
                                                productId: productId,
                                                orderNum: orderNum,
                                                startTimeStamp: startTimeStamp,
                                                endTimeStamp: endTimeStamp, nil)
        }
    }

    static func uploadContactsTracking(myx: String) {
        LYStocksManager.fetchUploadContactsInfo(myx: myx, nil)
    }
}
